package yangsw87.basic;

import java.util.Scanner;

import yangsw87.model.CdInfoVO;
import yangsw87.service.JDBCCdinfo;

public class J19_Cdinfo {

	private static final String title = "JDBC를 이용한 cdinfo프로그램";
	private static final String menu = ">>> 추가(1) 조회(2) 종료(0)";
	private static final String addmsg = "id, 제목, 출판사, 이름, 가격 순으로 입력하세요";
	
	public static void main(String[] args) {
		
		JDBCCdinfo cdsrv = new JDBCCdinfo();

		Scanner sc = new Scanner(System.in);

		while (true) {
			System.out.println(title);
			System.out.println(menu);

			switch (sc.nextInt()) {
			case 0:
				sc.close();
				System.exit(0); // 프로그램 종료
				break;
			case 1:
				addCdinfo(sc, cdsrv);
				break;
			case 2:
				showCdinfo(cdsrv);
				break;
			}

		}
	}

	private static void showCdinfo(JDBCCdinfo cdsrv) {
		
		System.out.println(cdsrv.readCDinfo());
	}

	private static void addCdinfo(Scanner sc, JDBCCdinfo cdsrv) {
		System.out.println(addmsg);
		
		CdInfoVO cd = new CdInfoVO(sc.next(), sc.next(), sc.next(), sc.next(), sc.nextInt());
		
		cdsrv.newCDinfo(cd);
	}
}
